package com.ruicar.afs.cloud.admin.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.ruicar.afs.cloud.common.core.entity.BaseEntity;
import com.ruicar.afs.cloud.common.core.security.vo.RoleVo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.beans.BeanUtils;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * <p>
 * 角色表
 * </p>
 *
 * @author Fzero
 * @since 2017-10-29
 */
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("sys_role")
public class SysRole extends BaseEntity<SysRole> {

	private static final long serialVersionUID = 1L;
	@NotBlank(message = "角色名称 不能为空")
	private String roleName;

	@NotBlank(message = "角色标识 不能为空")
	private String roleCode;

	@NotNull(message = "数据权限类型 不能为空")
	private String dsType;

	private String dsScope;

	private String tenantId;

	@TableField(exist = false)
	@ApiModelProperty(value = "拥有权限")
	private List<SysRolePermission> permissions;

	@TableField(exist = false)
	@ApiModelProperty(value = "拥有数据权限")
	private List<Long> departments;

	public RoleVo transToRoleVo(){
		RoleVo roleVo = new RoleVo();
		BeanUtils.copyProperties(this,roleVo);
		roleVo.setRoleId(this.getId().toString());
		return roleVo;
	}
}
